import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_learn_vi/src/bean/bean_train.dart';
import 'package:flutter_learn_vi/src/page/common/common_loading_dialog.dart';
import 'package:flutter_learn_vi/src/page/common/common_nodata_widget.dart';
import 'package:flutter_learn_vi/src/page/train/model/evaluate_model.dart';
import 'package:flutter_learn_vi/src/utils/toast_utils.dart';

import 'demo1/list_train_sign_item_widget.dart';

/// 创建人： Created by zhaolong
/// 创建时间：Created by  on 2021/1/16.
///
/// 可关注公众号：我的大前端生涯   获取最新技术分享
/// 可关注网易云课堂：https://study.163.com/instructor/1021406098.htm
/// 可关注博客：https://blog.csdn.net/zl18603543572
///
/// 打卡记录页面
///培训详情页面三
class TrainTabDetails3TeacherPage extends StatefulWidget {
  //培训ID
  final TrainApproveBean approveBean;

  const TrainTabDetails3TeacherPage({Key key, this.approveBean})
      : super(key: key);

  @override
  _TrainTabDetails3TeacherPageState createState() =>
      _TrainTabDetails3TeacherPageState();
}

class _TrainTabDetails3TeacherPageState
    extends State<TrainTabDetails3TeacherPage>
    with AutomaticKeepAliveClientMixin, EvaluateModel {
  @override
  bool get wantKeepAlive => true;

  @override
  void initState() {
    super.initState();
    _getList();
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    if (_isLoading) {
      return Center(
        child: LoadingWidget(),
      );
    }
    if (_list == null || _list.length == 0) {
      return NoDataWidget(
        text: "暂无打卡记录",
        clickCallBack: () {
          _getList();
        },
      );
    }
    return Column(
      children: [
        Container(
          alignment: Alignment.center,
          width: double.infinity,
          height: 74,
          padding: EdgeInsets.only(top: 10),
          child: Text(
            "签到记录",
            style: TextStyle(fontSize: 18),
          ),
          color: Colors.white,
        ),
        Expanded(
          child: Container(
            color: Colors.white,
            margin: EdgeInsets.only(top: 1),
            child: RefreshIndicator(
              onRefresh: () async {
                await _getList();
                ToastUtils.showToast("已刷新");
                return true;
              },
              child: ListView.builder(
                //条目个数
                itemCount: _list.length,
                //每个子条目的样式
                itemBuilder: (BuildContext context, int index) {
                  SignRecoderBean recoderBean = _list[index];
                  return ListItemTrainRecoderItem(
                    list: _list,
                    index: index,
                  );
                },
              ),
            ),
          ),
        )
      ],
    );
  }

  List<SignRecoderBean> _list;
  bool _isLoading = true;

  void _getList() async {
    _list =
        await getUserTrainSignRecoderList(trainId: widget.approveBean.trainId);
    _isLoading = false;
    if (mounted) {
      setState(() {});
    }
  }
}
